package mymyoux.utils
{
	public class UintHashUint implements IMap
	{
		private var _h:Hash;
		public function UintHashUint(weakKeys:Boolean=false){
			_h=new Hash(weakKeys);
		}
		/* ajouts */
		public function put(key:uint,value:uint):void{
			_h[key]=value;
		}		
		public function putAll(map:IMap):void{
			var r:Array=map.getKeys();
			for each(var i:String in r){
				_h[uint(i)]=uint(map.get(i));
			}
		}
		/* suppressions */
		public function remove(key:uint):void{
			_h[key]=null;
		}
		public function removeValue(value:uint):void{
			if(containsValue(value)){
				for each(var i:Object in getKeys()){
					if(_h[i]===value){
						_h[i]=null;
						if(!containsValue(value)){
							return;
						}
					}
				}
			}
		}
		public function clear():void{
			for each(var i:Object in getKeys()){
				_h[i]=null;
			}
		}
		/* tests */
		public function isEmpty():Boolean{
			for(var i:String in _h){
				return false;
			}
			return true;
		}
		public function containsKey(key:uint):Boolean{
			return _h[key]!=null;
		}
		public function containsValue(value:uint):Boolean{
			for each(var i:Object in _h){
				if(i===value){
					return true;
				}
			}
			return false;
		}
		/* récupération */
		public function get(key:Object):Object{
			return _h[uint(key)];
		}
		public function getKeys(value:Object=null):Array{
			var r:Array=new Array();
			for(var i:String in _h){
				if(value==null || value===_h[i]){
					r.push(uint(i));
				}
			}
			return r;
		}
		public function getValues():Array{
			var r:Array=new Array();
			for each(var i:Object in _h){
				r.push(uint(i));
			}
			return r;
		}
		public function clone():UintHashUint{
			var r:UintHashUint=new UintHashUint();
			r.putAll(_h);
			return r;
		}
		public function get length():uint{
			return getKeys().length;
		}
	}
}